﻿using System;
using System.Collections.Generic;
using System.Text;
using AbpDemo.Domain.Orders;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace AbpDemo.FluentConfigurations
{
    public class OrderConfiguration : IEntityTypeConfiguration<Order_1>
    {
        public void Configure(EntityTypeBuilder<Order_1> builder)
        {
            builder.ToTable("Orders");
            builder.HasKey(t => t.Id);
            builder.Property(t => t.Id).ValueGeneratedOnAdd();

            builder.Property(t => t.OrderNo).IsRequired().HasColumnType("varchar(32)");
            builder.Property(t => t.State).IsRequired();
            builder.Property(t => t.OrderAddress).HasColumnName("Address").HasMaxLength(512);
            builder.HasMany(t => t.Items).WithOne(i => i.Order).HasForeignKey(i => i.OrderId);
        }
    }
}
